package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-08-29
 * Time: 19:23
 */
import java.util.concurrent.Callable;

    //1.MyCallable类实现Callable接口
public class MyCallable implements Callable<String> {
    private int n;
    public MyCallable(int n){
        this.n = n;
    }

    //2.重写call方法
    @Override
    public String call() throws Exception {
        //描述线程的任务,返回线程执行返回后的结果,求1至n的和并返回结果
        int sum = 0;
        for (int i = 0; i <= n; i++) {
            sum += i;
        }
        return "线程求出的和为：" + sum;
    }
}
